import 'package:flutter/material.dart';
import 'package:check_app/widgets/PhoneSignal.dart';

class TabPages extends StatefulWidget {
  final List<String> tabs;
  final List<Widget> pages;
  const TabPages({Key key, this.tabs, this.pages}) : super(key: key);

  @override
  _TabPagesState createState() => _TabPagesState();
}

class _TabPagesState extends State<TabPages>
    with SingleTickerProviderStateMixin {
  TabController mController;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            color: Color.fromRGBO(255, 255, 255, 1),
            child: _tabBar(),
          ),
          PhoneSignal(),
          Expanded(
            flex: 1,
            child: _tabBarView(),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    mController.dispose();
  }

  @override
  void initState() {
    super.initState();

    mController = TabController(
      length: widget.tabs.length,
      vsync: this,
    );
  }

  Widget _tabBar() {
    return TabBar(
      //设置tab是否可水平滑动
      isScrollable: false,
      //控制器
      controller: mController,
      //设置tab文字得类型
      labelStyle: TextStyle(
        fontSize: 15,
        height: 21 / 15,
        fontWeight: FontWeight.w600,
      ),
      //设置tab选中得颜色
      labelColor: Colors.blue,
      //设置tab未选中得颜色
      unselectedLabelColor: Color.fromRGBO(150, 151, 154, 1),
      //设置自定义tab的指示器，CustomUnderlineTabIndicator
      //若不需要自定义，可直接通过
      //indicatorColor 设置指示器颜色
      //indicatorWight 设置指示器厚度
      indicatorPadding: EdgeInsets.fromLTRB(-10, 0, -10, 0),
      // indicatorSize  设置指示器大小计算方式
      // indicator: CustomUnderlineTabIndicator(
      //     strokeCap: StrokeCap.round,
      //     insets: EdgeInsets.only(left: 15, right: 15),
      //     borderSide: BorderSide(width: 4.0, color: Colors.red)),
      indicatorSize: TabBarIndicatorSize.label,
      tabs: widget.tabs.map((item) {
        return Container(
          child: Tab(text: item),
        );
      }).toList(),
    );
  }

  Widget _tabBarView() {
    return TabBarView(
      controller: mController,
      children: widget.pages,
    );
  }
}
